﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hp.Vertica.Migration.SqlServer
{
    public abstract class SqlDataTypeAllowMax : SqlDataTypeWithLength
    {
        public Boolean IsMax { get; set; }

        public SqlDataTypeAllowMax() { }

        public SqlDataTypeAllowMax(Int32 size) : base(size) { }

        public SqlDataTypeAllowMax(Boolean isMax)
        {
            this.IsMax = IsMax;
        }

        public override int Size
        {
            get
            {
                return base.Size;
            }
            set
            {
                if (value == Int32.MaxValue)
                {
                    this.IsMax = true;
                    base.Size = value;
                }
                else
                {
                    base.Size = value < this.MinSize ? this.MinSize : (value > this.MaxSize ? this.MaxSize : value);
                }
            }
        }

        public override string ToString()
        {
            if (this.IsMax)
            {
                return this.Name + "(MAX)";
            }
            else
            {
                return base.ToString();
            }
        }
    }
}
